{extend name="base/base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}
  <div class="layui-form-item layui-form-pane">
      <div class="layui-inline">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
          <select class="layui-input" name='status' id='status'>
            <option value="">全部</option>
            <option value="1">关闭</option>
            <option value="2">开启</option>
            <option value="3">升级关闭</option>
            <!-- <option value="4">已取消</option> -->
          </select>
        </div>
      </div>
    <div class="layui-inline">
            <label class="layui-form-label">智能云</label>
            <div class="layui-input-inline">
              <select class="layui-input" name='config_id' id='config_id'>
                <option value="">全部</option>
                {foreach $robot as $val}
                  <option value="{$val.id}">{$val.name}</option>
                {/foreach}
              </select>
            </div>
    </div>
      <!-- <div class="layui-inline">
        <label class="layui-form-label">买入币种</label>
        <div class="layui-input-inline">
          <select class="layui-input" name='wid' id='wid'>
            <option value="">全部</option>
            <option value="10">KY</option>
            <option value="1">USDT</option>
          </select>
        </div>
      </div> -->
      <div class="layui-inline">
          <label class="layui-form-label">用户ID</label>
          <div class="layui-input-inline">
              <input type="text" name="uid" autocomplete="off" class="layui-input" id='uid'>
          </div>
      </div>
      <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-inline">
              <input type="text" name="username" autocomplete="off" class="layui-input" id='username'>
          </div>
      </div>
    <div class="layui-inline">
          <label class="layui-form-label">下单时间</label>
          <div class="layui-input-inline">
              <input type="text" class="layui-input" name="start_time" id="start_time" placeholder="yyyy-MM-dd">
          </div>
          <div class="layui-form-mid">-</div>
          <div class="layui-input-inline">
              <input type="text" class="layui-input" name="end_time" id="end_time" placeholder="yyyy-MM-dd">
          </div>
      </div>
    <!--   <div class="layui-inline">
          <label class="layui-form-label">电话</label>
          <div class="layui-input-inline">
              <input type="text" name="phone" autocomplete="off" class="layui-input" id='phone'>
          </div>
      </div> -->
      <div class="layui-inline">
        <div class="demoTable">
          <button class="layui-btn" data-type="reload">搜索</button>
        </div>
      </div>
        <script type="text/html" id="edit">
    <a class="layui-btn layui-btn-xs" lay-event="edit">开启/关闭</a>

  </script>
  <table id="table" lay-filter="table"></table> 
</div>
{/block}
{block name="script"}
<script>
layui.use(['table', 'laydate'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  table.render({
    elem: '#table'
    ,height: 'full-200'
    ,url: '/admin/invest/recordList/' //数据接口
    ,limit:20
    ,page: true //开启分页
    ,id:'reload'
    ,cols: [[ //表头
        {field:'uid', title: '用户ID', width: 100}
        ,{field:'username', title: '电话', width: 150}
        ,{field:'name', title: '智能云名称', width: 150}
        ,{field:'orderno', title: '订单编号', width: 150}
        // ,{field:'name', title: '用户名', width: 150}
        ,{field:'cost', title: '实际花费（usdt）', width: 200}
        ,{field:'price', title: '价格（usdt）', width: 200}
        ,{field:'order_date', title: '下单时间', width: 200}
        ,{field:'status', title: '状态', width: 200,templet: function(d){
          if (d.status == 1) {
            return '<span style="color:blue">关闭</span>'
          }
          if (d.status == 2) {
            return '<span style="color:red">开启</span>'
          }
          if (d.status == 3) {
            return '<span style="color:green">升级关闭</span>'
          }
          // if (d.status == 4) {
          //   return '<span style="color:blue">区块确认失败</span>'
          // }
        }}
        ,{field:'type', title: '类型', width: 200,templet: function(d){
          if (d.type == 1) {
            return '<span style="color:blue">注册赠送</span>'
          }
          if (d.type == 2) {
            return '<span style="color:red">直接购买</span>'
          }
          if (d.type == 3) {
            return '<span style="color:green">兑换码</span>'
          }
          if (d.type == 4) {
            return '<span style="color:black">优惠券</span>'
          }
        }}
        ,{field:'open_date', title: '开启时间', width: 200}
        ,{field:'open_type', title: '开启类型', width: 200,templet: function(d){
          if (d.open_type == 0) {
            return '<span style="color:green">未执行</span>'
          }
          if (d.open_type == 1) {
            return '<span style="color:blue">用户开启</span>'
          }
          if (d.open_type == 2) {
            return '<span style="color:red">后台开启</span>'
          }
          // if (d.status == 4) {
          //   return '<span style="color:blue">区块确认失败</span>'
          // }
        }}
        ,{field:'close_date', title: '关闭时间', width: 200}
        ,{field:'close_type', title: '关闭类型', width: 200,templet: function(d){
          if (d.close_type == 0) {
            return '<span style="color:green">未执行</span>'
          }
          if (d.close_type == 1) {
            return '<span style="color:blue">自动关闭</span>'
          }
          if (d.close_type == 2) {
            return '<span style="color:red">后台关闭</span>'
          }
          // if (d.status == 4) {
          //   return '<span style="color:blue">区块确认失败</span>'
          // }
        }}
        //,{field:'is_active', title: '激活', width: 250,templet: function(d){
        //  if (d.is_active == 1) {
        //     return '<span style="color:red">已激活</span>'
        //   }
        //   if (d.is_active == 0) {
        //     return '<span style="color:blue">待激活</span>'
        //   }
        //}}
        ,{title: '操作', toolbar: '#edit', width: 200}
    ]]
  });
  table.on('tool(table)', function(obj){
      var data = obj.data;
    //    if(obj.event === 'edit'){
    //     $.ajax({
    //         url:"{:url('admin/invest/active')}",
    //         type:"POST",
    //         data:{id:data.id},
    //         success:function(ret){
    //             if (ret.code == 0) {
    //               layer.msg(ret.msg);
    //               $(".layui-laypage-btn")[0].click(); 
    //             }
    //             if (ret.code == 1) {
    //                 layer.msg(ret.msg);
    //             }
    //         }
    //     }); 
    // }
     if(obj.event === 'edit'){
        $.ajax({
            url:"{:url('admin/invest/active')}",
            type:"POST",
            data:{id:data.id},
            success:function(ret){
                if (ret.code == 0) {
                  $(".layui-laypage-btn")[0].click(); 
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                }
            }
        }); 
    }
    });
  // 搜索
  var $ = layui.$, active = {
        reload: function(){
            table.reload('reload', {
                where: {
                    username: $('#username').val(),
                    uid: $('#uid').val(),
                    status: $('#status').val(),
                    config_id: $('#config_id').val(),
                    // is_active: $('#is_active').val(),
                    phone:$('#phone').val(),
                    start_time: $('#start_time').val(),
                    end_time: $('#end_time').val()
                }
            });
        }
    };
    $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';

  });

  //日期
  laydate.render({
    elem: '#start_time'
  });
  laydate.render({
    elem: '#end_time'
  });
});
</script>
{/block}
